package com.xiaolin.oa.controller;

import com.xiaolin.oa.annotations.HasApi;
import com.xiaolin.oa.constants.ApiPermConstant;
import com.xiaolin.oa.model.dto.SysMenuTree;
import com.xiaolin.oa.model.entity.SysMenu;
import com.xiaolin.oa.service.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaolin
 * @description 描述
 * @since 2024/7/12
 */
@Api("菜单资源")
@RestController
@RequestMapping("/menu")
public class SysMenuController {

    @Autowired
    private SysMenuService menuService;

    @HasApi({ApiPermConstant.COMMON_PERM})
    @ApiOperation("获取菜单树")
    @PostMapping("/getTree")
    public List<SysMenuTree> getMenuTree(@RequestBody SysMenu menu) {
        return menuService.getMenuTree(menu);
    }

    @HasApi({"menu:add"})
    @ApiOperation("添加菜单")
    @PostMapping("/add")
    public boolean addMenu(@RequestBody SysMenu menu) {
        return menuService.addMenu(menu);
    }

    @HasApi({"menu:get"})
    @ApiOperation("获取菜单")
    @PostMapping("/get/{id}")
    public SysMenu getMenu(@PathVariable("id") Integer id) {
        return menuService.getMenu(id);
    }

    @HasApi({"menu:update"})
    @ApiOperation("修改菜单")
    @PostMapping("/update")
    public boolean updateMenu(@RequestBody SysMenu menu) {
        return menuService.updateMenu(menu);
    }

    @HasApi({"menu:enable"})
    @ApiOperation("启用禁用")
    @PostMapping("/status/{id}/{status}")
    public boolean status(@PathVariable Integer id, @PathVariable String status) {
        return menuService.status(id, status);
    }

    @HasApi({"menu:del"})
    @ApiOperation("删除菜单")
    @PostMapping("/delete/{id}")
    public boolean deleteMenu(@PathVariable Integer id) {
        return menuService.deleteMenu(id);
    }
}
